﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entalpy.dto;
using Entalpy.Controller;

namespace Entalpy
{
    public partial class MainForm : Form
    {
        private string path;
        private IDictionary<double, double> Relation;
        private IDictionary<double, double> Points;
        private void GetGistogram()
        {
            IDictionary<double,int> ExperimentResult = ProcessFactory.GetGistogram(ProcessFactory.ReadData(path));

            chart_gistogram.Series["Series1"].Points.DataBindXY(ExperimentResult.Keys, ExperimentResult.Values);
            
        }
        private void GetRelation()
        {
            Relation = ProcessFactory.GetRelation(ProcessFactory.ReadData(path));
            chart_entalpy.Series["Series2"].Points.DataBindXY(Relation.Keys, Relation.Values);
            Points = ProcessFactory.GetLeastSquaresPoints(Relation);
            chart_entalpy.Series["Series1"].Points.DataBindXY(Points.Keys, Points.Values);
        }

        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void chart_gistogram_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (tb_basis.Text != "")
            {
                GetRelation();
                tb_delta.Text = ProcessFactory.GetDelta(Relation, Points).ToString();
                tb_entalpy.Text = ProcessFactory.GetEntalpy(Relation).ToString();
            }
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void загрузитьДанныеToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog mydialog = new OpenFileDialog();
            mydialog.CheckFileExists = true;
            mydialog.Multiselect = false;

            if (mydialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                path = mydialog.FileName;
                btn_basis_get.Enabled = true;
                GetGistogram();
            }
        }

        private void btn_basis_get_Click(object sender, EventArgs e)
        {
            if (path != "")
            {
                tb_basis.Text = ProcessFactory.GetBasis(ProcessFactory.ReadData(path)).ToString();
               
            }
            else MessageBox.Show("Данные не готовы!");
        }
    }
}
